package boltdbs

import (
	"github.com/boltdb/bolt"
	"log"
)

var (
	db     *bolt.DB
	DBUser = []byte("users")
	DBRate = []byte("rates")
)

func init() {
	var err error
	db, err = bolt.Open("./boltdbs/session.db", 0600, nil)
	if err != nil {
		log.Panic(err)
	}

	var tables = [][]byte{DBUser, DBRate}
	err = db.Update(func(tx *bolt.Tx) error {
		for _, l := range tables {
			_, err := tx.CreateBucketIfNotExists(l)
			if err != nil {
				panic(err)
			}
		}
		return nil
	})
	if err != nil {
		panic(err)
	}
}

func GetDb() *bolt.DB {
	return db
}
